import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/TbContractor/tbContractor/list',
  save= '/TbContractor/tbContractor/add',
  edit= '/TbContractor/tbContractor/edit',
  deleteOne = '/TbContractor/tbContractor/delete',
  deleteBatch = '/TbContractor/tbContractor/deleteBatch',
  importExcel = '/TbContractor/tbContractor/importExcel',
  exportXls = '/TbContractor/tbContractor/exportXls',
  tbContractorSafetyPermitList = '/TbContractor/tbContractor/listTbContractorSafetyPermitByMainId',
  tbContractorSafetyPermitSave= '/TbContractor/tbContractor/addTbContractorSafetyPermit',
  tbContractorSafetyPermitEdit= '/TbContractor/tbContractor/editTbContractorSafetyPermit',
  tbContractorSafetyPermitDelete = '/TbContractor/tbContractor/deleteTbContractorSafetyPermit',
  tbContractorSafetyPermitDeleteBatch = '/TbContractor/tbContractor/deleteBatchTbContractorSafetyPermit',
  tbContractorBusinessLicenseList = '/TbContractor/tbContractor/listTbContractorBusinessLicenseByMainId',
  tbContractorBusinessLicenseSave= '/TbContractor/tbContractor/addTbContractorBusinessLicense',
  tbContractorBusinessLicenseEdit= '/TbContractor/tbContractor/editTbContractorBusinessLicense',
  tbContractorBusinessLicenseDelete = '/TbContractor/tbContractor/deleteTbContractorBusinessLicense',
  tbContractorBusinessLicenseDeleteBatch = '/TbContractor/tbContractor/deleteBatchTbContractorBusinessLicense',
  tbContractorAptitudeList = '/TbContractor/tbContractor/listTbContractorAptitudeByMainId',
  tbContractorAptitudeSave= '/TbContractor/tbContractor/addTbContractorAptitude',
  tbContractorAptitudeEdit= '/TbContractor/tbContractor/editTbContractorAptitude',
  tbContractorAptitudeDelete = '/TbContractor/tbContractor/deleteTbContractorAptitude',
  tbContractorAptitudeDeleteBatch = '/TbContractor/tbContractor/deleteBatchTbContractorAptitude',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({ url: Api.list, params });

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params },{ isTransformResponse: false });
}
  
/**
 * 列表接口
 * @param params
 */
export const tbContractorSafetyPermitList = (params) => {
  if(params['contractorId']){
    return defHttp.get({ url: Api.tbContractorSafetyPermitList, params });
  }
  return Promise.resolve({});
}

/**
 * 删除单个
 */
export const tbContractorSafetyPermitDelete = (params,handleSuccess) => {
  return defHttp.delete({ url: Api.tbContractorSafetyPermitDelete, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 */
export const tbContractorSafetyPermitDeleteBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.tbContractorSafetyPermitDeleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 */
export const  tbContractorSafetyPermitSaveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.tbContractorSafetyPermitEdit : Api.tbContractorSafetyPermitSave;
  return defHttp.post({ url: url, params },{ isTransformResponse: false });
}

/**
 * 导入
 */
export const tbContractorSafetyPermitImportUrl = '/TbContractor/tbContractor/importTbContractorSafetyPermit'

/**
 * 导出
 */
export const tbContractorSafetyPermitExportXlsUrl = '/TbContractor/tbContractor/exportTbContractorSafetyPermit'
  
/**
 * 列表接口
 * @param params
 */
export const tbContractorBusinessLicenseList = (params) => {
  if(params['contractorId']){
    return defHttp.get({ url: Api.tbContractorBusinessLicenseList, params });
  }
  return Promise.resolve({});
}

/**
 * 删除单个
 */
export const tbContractorBusinessLicenseDelete = (params,handleSuccess) => {
  return defHttp.delete({ url: Api.tbContractorBusinessLicenseDelete, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 */
export const tbContractorBusinessLicenseDeleteBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.tbContractorBusinessLicenseDeleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 */
export const  tbContractorBusinessLicenseSaveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.tbContractorBusinessLicenseEdit : Api.tbContractorBusinessLicenseSave;
  return defHttp.post({ url: url, params },{ isTransformResponse: false });
}

/**
 * 导入
 */
export const tbContractorBusinessLicenseImportUrl = '/TbContractor/tbContractor/importTbContractorBusinessLicense'

/**
 * 导出
 */
export const tbContractorBusinessLicenseExportXlsUrl = '/TbContractor/tbContractor/exportTbContractorBusinessLicense'
  
/**
 * 列表接口
 * @param params
 */
export const tbContractorAptitudeList = (params) => {
  if(params['contractorId']){
    return defHttp.get({ url: Api.tbContractorAptitudeList, params });
  }
  return Promise.resolve({});
}

/**
 * 删除单个
 */
export const tbContractorAptitudeDelete = (params,handleSuccess) => {
  return defHttp.delete({ url: Api.tbContractorAptitudeDelete, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 */
export const tbContractorAptitudeDeleteBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.tbContractorAptitudeDeleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 */
export const  tbContractorAptitudeSaveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.tbContractorAptitudeEdit : Api.tbContractorAptitudeSave;
  return defHttp.post({ url: url, params },{ isTransformResponse: false });
}

/**
 * 导入
 */
export const tbContractorAptitudeImportUrl = '/TbContractor/tbContractor/importTbContractorAptitude'

/**
 * 导出
 */
export const tbContractorAptitudeExportXlsUrl = '/TbContractor/tbContractor/exportTbContractorAptitude'
